package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName Controller
 * @Description: TODO
 * @Author ChenYuan
 * @Date 2020/11/18
 * @Version V1.0
 **/
@RestController
@RequestMapping
@Api(value = "用户接口",tags = "用户")
@EnableTransactionManagement
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "测试接口",notes = "测试用户接口",response = User.class)
    @GetMapping(value = "/test",produces = "application/json;charset=utf-8")
    private String getUser(){
        List<User> user = userService.getUser();
        return JSON.toJSONString(user);
    }

    @ApiOperation(value = "测试事务失效",notes = "测试事务失效",response = User.class)
    @GetMapping(value = "/add",produces = "application/json;charset=utf-8")
    private String addUser(boolean isEx){
        userService.addUser(isEx);
        return JSON.toJSONString("success");
    }
}
